package com.yequan.drawerlayoutdemo;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.view.LayoutInflaterCompat;
import android.support.v4.view.LayoutInflaterFactory;
import android.support.v7.app.AppCompatActivity;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

public class TestFactoryActivity extends AppCompatActivity {

    private static final String TAG = "TestFactoryActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        LayoutInflater mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        LayoutInflaterCompat.setFactory(mInflater, new LayoutInflaterFactory() {
            @Override
            public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
                Log.i(TAG, "onCreateView: " + "name::" + name);
                for (int i = 0; i < attrs.getAttributeCount(); i++) {
                    String attributeName = attrs.getAttributeName(i);
                    String attributeValue = attrs.getAttributeValue(i);
                    Log.i(TAG, "onCreateView: " + "attributeName::" + attributeName + "::::"+"attributeValue::" + attributeValue);
                }
                if (name.equals("ImageView")) {
                    return new TextView(context, attrs);
                }
                return null;
            }
        });
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test_factory);
    }
}
